<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>js</title>
</head>
<style>
	img{
		cursor: pointer;
		position: absolute;
		top:0px;
		left:0px;
	}
</style>
<body>
	<img src="a.jpg" alt="" id="imgid" style="width:400px; height:300px;" >
</body>

<script>


imgobj=document.getElementById('imgid');

i=0;
imgobj.onclick=function(){

	if(i%2==0){
		this.src='b.jpg';
		
	}else{
		this.src='a.jpg';
	}
	i++;
}

</script>
</html>